var host = "http://localhost:8080";
var wshost = "ws://localhost:8080/handler";
var ctx = "/chatroom";
function getToken() {
    var cookies = document.cookie;
    var cks = cookies.split(";");
    for (var i = 0; i < cks.length; i++) {
        var values = cks[i].split(",");
        for (var j = 0; j < values.length; j++) {
            var vv = values[j].split("=");
            if (vv[0].trim() == 'token') {
                return vv[1];
            }
        }

    }

    return "";
}

function checkServer(callback) {
    $.get(host+"/api/index",function (data,status) {
        callback(data)
    })
}

function CMPostServer(url,data,callback) {
    data.token = getToken()
    $.post(host+url,data,function (data,status) {
        if (data.code == 401){
            window.location = ctx+"/user/login.html"
        }
        callback(data)
    })
}

function CMGetServer(url,data,callback) {
    data.token = getToken();
    $.get(host+url,data,function (data,status) {
        if (data.code == 401){
            window.location = ctx+"/user/login.html"
        }
        callback(data)
    })
}

function checkLogin() {

}

function setToken(tk) {
    document.cookie = "token="+tk;
}
